﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Web.Security;

public partial class MyAdmin_QuanLy : QL_MasterPage
{
    protected bool isAdmin;

    protected void Page_Load(object sender, EventArgs e)
    {
    }

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

        this.quyen = QuyenTruyCap.CamTruyCap;

        var cfg = (System.Web.Configuration.CompilationSection)System.Configuration.ConfigurationManager.GetSection("system.web/compilation");
        if (cfg.Debug)
        {
            Helper.setCurrentAminUserName(Session, "am");
            Helper.setCurrentAdminRole(Session, "b257b9f6-a5cb-4aee-80a3-ab012201fc92");
            this.quyen = QuyenTruyCap.QuyenChinhSua;
        }

        string pageName = Helper.getCurrentPageName(Request.Url);
        string role = Helper.getCurrentAdminRole(Session);

        Helper.setWantedPage(Session, pageName);

        if (role == null)
        {
            Response.Redirect("Login.aspx");
        }
        else
        {
            isAdmin = DataAccess_Layer.RoleDAC.isAdmin(role);
            if (isAdmin)
            {
                this.quyen = QuyenTruyCap.QuyenChinhSua;
            }
            else
            {
                DataAccess_Layer.PhanQuyen pq = DataAccess_Layer.PhanQuyenDAC.layPhanQuyen(pageName, role);
                if (pq == null)
                {
                    Response.Redirect("Login.aspx");
                }

                this.quyen = pq.Quyen.Value;
            }

            userNameHYPERLINK.Text = "Xin chào " + Helper.getCurrentAdminUserName(Session);
            userNameHYPERLINK.NavigateUrl = "QL_TaiKhoan_AM.aspx";
        }
    }
}
